<html>
<head><meta charset="utf-8"><title>How to get position from ast::Comment · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20to.20get.20position.20from.20ast.3A.3AComment.html">How to get position from ast::Comment</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="220566699"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20to%20get%20position%20from%20ast%3A%3AComment/near/220566699" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> sasurau4 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20to.20get.20position.20from.20ast.3A.3AComment.html#220566699">(Dec 21 2020 at 09:32)</a>:</h4>
<p>I'm working on <a href="https://github.com/rust-analyzer/rust-analyzer/issues/6168">https://github.com/rust-analyzer/rust-analyzer/issues/6168</a><br>
If the doc comment has multiple link, we need to determine which link is pointed from position.offset. In basic source code, it can be easily done by file.token_at_offset method but comment has only non-structured &amp;str. What is the best way to get position from doc comment?</p>
<div class="codehilite"><pre><span></span><code>/// Blah, .. [`foo`]&lt;|&gt; is [`bar`] ...
</code></pre></div>



<a name="220588268"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20to%20get%20position%20from%20ast%3A%3AComment/near/220588268" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20to.20get.20position.20from.20ast.3A.3AComment.html#220588268">(Dec 21 2020 at 14:21)</a>:</h4>
<p><span class="user-mention" data-user-id="331219">@sasurau4</span> couldn't you do <code>doc_comment[start..end]</code>?</p>



<a name="220588287"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20to%20get%20position%20from%20ast%3A%3AComment/near/220588287" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20to.20get.20position.20from.20ast.3A.3AComment.html#220588287">(Dec 21 2020 at 14:22)</a>:</h4>
<p>or hmm I don't know if <code>offset</code> is a number or a range</p>



<a name="220590590"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20to%20get%20position%20from%20ast%3A%3AComment/near/220590590" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> sasurau4 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20to.20get.20position.20from.20ast.3A.3AComment.html#220590590">(Dec 21 2020 at 14:46)</a>:</h4>
<p>Yeah, I could do <code>doc_comment[start..end]</code> if I knew where infra link the FilePosition indicates. But FilePosition has only the offset of the file, so I have to determine where the offset is included by intra link range. <br>
I tried parsing doc comment by pulldown_cmark, it emit only Event that doesn't contain any position infos. <br>
The change of intra link to ast seems very difficult.</p>



<a name="220593942"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20to%20get%20position%20from%20ast%3A%3AComment/near/220593942" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20to.20get.20position.20from.20ast.3A.3AComment.html#220593942">(Dec 21 2020 at 15:19)</a>:</h4>
<p>Pulldown_cmark will give you the span if you call into_offset_iter</p>



<a name="220681453"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20to%20get%20position%20from%20ast%3A%3AComment/near/220681453" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> sasurau4 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20to.20get.20position.20from.20ast.3A.3AComment.html#220681453">(Dec 22 2020 at 11:47)</a>:</h4>
<p>It seems great!  Thanks</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>